//
//  MATabBarViewController.m
//  meiang_edu
//
//  Created by Liubi_Chaos_G on 2018/7/30.
//  Copyright © 2018年 com.meiang.meiang_edu. All rights reserved.
//

#import "MATabBarViewController.h"

#import "MANavigationController.h"

#import "MAHomeViewController.h"
#import "MAFunctionViewController.h"

#import <RDVTabBarItem.h>

@interface MATabBarViewController ()<RDVTabBarControllerDelegate>

@end

@implementation MATabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    MAHomeViewController *homeVC = [[MAHomeViewController alloc] init];
    MANavigationController *nav1 = [[MANavigationController alloc] initWithRootViewController:homeVC];
    
    MAFunctionViewController *funVC = [[MAFunctionViewController alloc] init];
    MANavigationController *nav2 = [[MANavigationController alloc] initWithRootViewController:funVC];
    
    //    [self.rdv_tabBarController setHidesBottomBarWhenPushed:YES];
    [self setViewControllers:@[nav1,nav2]];
    self.delegate = self;
    [self customizeTabBarForController:self];
}

- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
    
    self.tabBar.frame = CGRectMake(0, 0, SCREEN_WIDTH, 48);
    if (IS_IPHONE_X) {
        self.tabBar.frame = CGRectMake(0, 0, SCREEN_WIDTH, 73);
    }
    self.tabBar.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    self.tabBar.layer.shadowOffset = CGSizeMake(0, 0);
    self.tabBar.layer.shadowOpacity = 0.3;
    NSArray *tabBarItemImages = @[@"home", @"function"];
    NSArray *tabBarItemTitles = @[@"",@""];
    NSInteger index = 0;
    for (RDVTabBarItem *tabberItem in [[tabBarController tabBar] items]) {
        
        UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_hl", [tabBarItemImages objectAtIndex:index]]];
        UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@", [tabBarItemImages objectAtIndex:index]]];
        
        [tabberItem setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
        [tabberItem setTitle:[tabBarItemTitles objectAtIndex:index]];
        
        
        if (IS_IPHONE_X) {
            [tabberItem setTitle:[tabBarItemTitles objectAtIndex:index]];
            tabberItem.imagePositionAdjustment = UIOffsetMake(0, -5);
            
            tabberItem.titlePositionAdjustment = UIOffsetMake(0, 3);
            
            index++;
            
        } else {
            tabberItem.titlePositionAdjustment = UIOffsetMake(0, 8);
            index++;
        }
    }
    
    self.tabBar.backgroundView.backgroundColor = [UIColor whiteColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)hiddenTabbar:(BOOL)value {
    [self.rdv_tabBarController setTabBarHidden:value animated:YES];
}
- (void)hiddenNav:(BOOL)value {
    [self.navigationController setNavigationBarHidden:value animated:NO];
}

#pragma mark - RDVTabBarControllerDelegate
/**
 * Asks the delegate whether the specified view controller should be made active.
 */
- (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    return YES;
}

/**
 * Tells the delegate that the user selected an item in the tab bar.
 */
- (void)tabBarController:(RDVTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    DLog(@"");
}

@end
